var base = require('/base_info.js');
var utils = require('/utils/index.js');
// 富文本解析
var wxParse = require('/pages/wxParse-master/wxParse.js');
Page({
  data: {
    imgUrl: base.imgUrl,
    hotelInfo: {},
    swiperIndex: 0,
    hotList: [],
    // 房间介绍缓存
    introduction: my.getStorageSync({
      key: "introduction"
    }).data,
    serviceList: [
      {
        ishave:0,
        img1: '/images/s-wifi-select.png',
        img2: '/images/s-wifi-unselect.png',
        text:'免费wifi'
      }, {
        ishave: 0,
        img1: '/images/s-park-select.png',
        img2: '/images/s-park-unselect.png',
        text: '免费停车'
      }, {
        ishave: 0,
        img1: '/images/s-meal-select.png',
        img2: '/images/s-meal-unselect.png',
        text: '餐厅'
      }, {
        ishave: 0,
        img1: '/images/s-luggage-select.png',
        img2: '/images/s-luggage-unselect.png',
        text: '行李寄存'
      }, {
        ishave: 0,
        img1: '/images/s-exercise-select.png',
        img2: '/images/s-exercise-unselect.png',
        text: '健身房'
      }, {
        ishave: 0,
        img1: '/images/s-fly-select.png',
        img2: '/images/s-fly-unselect.png',
        text: '接机服务'
      }, {
        ishave: 0,
        img1: '/images/s-meeting-select.png',
        img2: '/images/s-meeting-unselect.png',
        text: '会议服务'
      }, {
        ishave: 0,
        img1: '/images/s-swim-select.png',
        img2: '/images/s-swim-unselect.png',
        text: '游泳池'
      }
    ],
    cardList:[
      '/images/card1.png',
      '/images/card2.png',
      '/images/card3.png',
      '/images/card4.png',
      '/images/card5.png',
      '/images/bank.png'
    ],
    card_type: [0, 0, 0, 0, 0, 0],
    showToggle:false,//是否显示弹窗 
    title:"",//弹窗标题
    showMain:"",//显示内容
    shouModel: 1
  },
  // 点击显示弹窗
  introduceToggle(e) {
    var that = this;
    console.log(e.currentTarget.dataset.id);
    if (e.currentTarget.dataset.id == 'preKonw') {
      that.setData({
        title: "预订须知",
        shouModel: 1
      });
    } else if (e.currentTarget.dataset.id == 'hotelSet'){
      that.setData({
        title: "酒店设施",
        shouModel: 2
      });
    } else {
      that.setData({
        title: "酒店简介",
        shouModel: 3
      });
    }
    that.setData({
      showToggle: !that.data.showToggle
    });
  },
  closeClick(){
    var that = this;
    that.setData({
      showToggle: false,
    });
  },
  //拨打电话
  makePhoneCall() {
    my.makePhoneCall({ number: this.data.hotelInfo.tel }); 
  },
  // 获取酒店详情
  getData () {
    let that = this;
    // my.showLoading({});
    // utils.getData('SingleSystemDetails', {}, function(res){
    //   console.log(res.data.data);
    //   my.hideLoading();
    //   wxParse.wxParse('introduction', 'html', res.data.data.introduction ? res.data.data.introduction : "<p style='color: #666;'>暂无酒店介绍</p>", that, 5);
    //   // 设备设施
    //   wxParse.wxParse('equipment', 'html', res.data.data.service_facility ? res.data.data.service_facility : "<p style='color: #666;'>暂无设施信息</p>", that, 5);
    // }, function () {
    //   my.hideLoading();
    // })
    var hotel_info = JSON.parse(my.getStorageSync({
      key: 'hotel_info', // 缓存数据的key
    }).data);
    wxParse.wxParse('equipment', 'html', hotel_info.service_facility ? hotel_info.service_facility : "<p style='color: #666;'>暂无设施信息</p>", that, 5);
    wxParse.wxParse('equipment', 'html', hotel_info.service_facility ? hotel_info.service_facility : "<p style='color: #666;'>暂无设施信息</p>", that, 5);
    that.setData({
      hotel_info: hotel_info
    });
    that.setData({
      hotList: hotel_info.img.split(','),
      hotelInfo: hotel_info,
      card_type: hotel_info.card_type,
      serviceList: [
        {
          ishave: hotel_info.wifi,
          img1: '/images/s-wifi-select.png',
          img2: '/images/s-wifi-unselect.png',
          text: '免费wifi'
        }, {
          ishave: hotel_info.park,
          img1: '/images/s-park-select.png',
          img2: '/images/s-park-unselect.png',
          text: '免费停车'
        }, {
          ishave: hotel_info.breakfast,
          img1: '/images/s-meal-select.png',
          img2: '/images/s-meal-unselect.png',
          text: '餐厅'
        }, {
          ishave: hotel_info.luggage,
          img1: '/images/s-luggage-select.png',
          img2: '/images/s-luggage-unselect.png',
          text: '行李寄存'
        }, {
          ishave: hotel_info.gym,
          img1: '/images/s-exercise-select.png',
          img2: '/images/s-exercise-unselect.png',
          text: '健身房'
        }, {
          ishave: hotel_info.airport,
          img1: '/images/s-fly-select.png',
          img2: '/images/s-fly-unselect.png',
          text: '接机服务'
        }, {
          ishave: hotel_info.boardroom,
          img1: '/images/s-meeting-select.png',
          img2: '/images/s-meeting-unselect.png',
          text: '会议服务'
        }, {
          ishave: hotel_info.swim,
          img1: '/images/s-swim-select.png',
          img2: '/images/s-swim-unselect.png',
          text: '游泳池'
        }
      ]
    });
    // 订购须知
    wxParse.wxParse('rule', 'html', hotel_info.rule ? hotel_info.rule + "</br>" + hotel_info.pet + "</br>" + ",不接受18岁以下客人在无监护人的陪同的情况下入住" : "<p style='color: #666;'>暂无订购须知</p>", that, 5);
  },
  //滑动获取选中商品
  getSelectItem: function(e) {
    var that = this;
    var itemWidth = e.detail.scrollWidth / that.data.hotList.length;//每个商品的宽度
    var scrollLeft = e.detail.scrollLeft;//滚动宽度
    var curIndex = Math.round(scrollLeft / itemWidth);//通过Math.round方法对滚动大于一半的位置进行进位
    console.log(curIndex);
    that.setData({
      swiperIndex: curIndex
    });
    that.setData({
      hotList: that.data.hotList,
    });
  },
  // 点击跳转到地图页面
  addressClick () {
    my.navigateTo({
      url: './../map/map'
    });
  },
  onLoad(query) {
    console.log(query);
    this.getData();
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: my.getStorageSync({
        key: 'hotel_name', // 缓存数据的key
      }).data,
      desc: my.getStorageSync({
        key: 'my_app_description', // 缓存数据的key
      }).data,
      path: 'pages/index/index?share=true',
      success: function (e) {
        console.log(e);
      }
    };
  },
});
